<template xmlns="http://www.w3.org/1999/html">
  <div class="content">
    <div class="title">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }"><b>系统</b></el-breadcrumb-item>
        <el-breadcrumb-item>账号管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="main-content">
      <el-form :label-position="labelPosition" label-width="120px" v-model="requestContent" style="margin-left: 30px">
        <el-form-item label="dataId" v-show="false">
          <el-input v-model="requestContent.dataId" placeholder="请输入内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="数据组名" v-show="false">
          <el-input v-model="requestContent.dataGroup" placeholder="请输入内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="名称">
          <el-input v-model="requestContent.name" placeholder="请输入内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="代码">
          <el-input v-model="requestContent.code" placeholder="请输入内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="助记码">
          <el-input v-model="requestContent.mnemonicCode" placeholder="请输入内容" style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="requestContent.remark" placeholder="请输入内容" style="width: 200px"></el-input>
        </el-form-item>
         <el-form-item>
          <el-button type="primary" @click="keepMetaData">保存</el-button>
          <el-button type="primary" @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import ElCol from 'element-ui/packages/col/src/col'
  import ElForm from '../../../node_modules/element-ui/packages/form/src/form.vue'
  import ElFormItem from '../../../node_modules/element-ui/packages/form/src/form-item.vue'
  import axios from 'axios'
  export default {
    components: {
      ElFormItem,
      ElCol,ElForm},
    data () {
      return {
        labelPosition:'left',
        requestContent:{
          dataId:'',
          dataGroup:'',
          name:'',
          code:'',
          mnemonicCode:'',
          remark:''
        }
      }
    },
    methods:{
      keepMetaData:function(){
        if(this.requestContent.dataId==''){
          this.$http.post("/dataDict/"+this.requestContent.dataGroup+"/data",this.requestContent)
          .then((response)=>{
            if(response.data.success){
              this.$message("保存成功")
            }
          })
          .catch(function(error){
            console.log(error)
          })
        }else{
          this.$http.put("/dataDict/"+this.requestContent.dataGroup+"/"+this.requestContent.dataId,this.requestContent)
          .then((response)=>{
            this.$message("修改成功")
          })
          .catch(function(error){
            console.log(error)
          })
        }
      }
    },

    mounted() {
       if(this.$route.query.group){
        this.requestContent.dataGroup=this.$route.query.group;
      }
      if(this.$route.query.content){
        this.requestContent=this.$route.query.content
      }
    }
  }
</script>

<style lang="scss" scoped>
.content {
  padding: 10px;
  background: #F7F7F7;
  .title {
    color: #99A9BF;
    font-size: 14px;
    line-height: 18px;
    margin: 8px 0px 10px 0px;
  }
  .main-content {
    background: #fff;
    position: fixed;
    top: 96px;
    bottom: 10px;
    left: 216px;
    right: 16px;
    overflow: auto;
    padding: 20px;
  }
}
</style>
